home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / com / internet / sting / shttpd20 / demo / cgi-src / the_cloc / the_cloc.c < prev   
Encoding:
C/C++ Source or Header  |  1997-01-24  |  1.7 KB  |  65 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5. #define INT(x) (x-floor(x)>=0.5)?(int)ceil(x):(int)floor(x)
  6.  
  7. void main (void)
  8. {
  9. unsigned long line[32];    /* Le bitmap */
  10. long epoch;             /* gestion de */
  11. struct tm *tp;          /* l'heure   */
  12. double x,y, heure, minute;  /* les coordonnees et l'heure */
  13. int j, i;
  14. char res[8], tmp[10];
  15.  
  16. /* Creation de l'entete */
  17.  
  18. printf ("Content-type: image/x-xbitmap%c%c",10,10);
  19.  
  20. /* Creation du corps */
  21. printf("#define count_width 32\n");
  22. printf("#define count_height 32\n");
  23. printf("static char count_bits[] = {\n");
  24.  
  25. /* Mise a zero */
  26. for (j=0; j<32; j++) line[j]=0;
  27.  
  28. /* On dessine le cadran de l'horloge */
  29. for (i=0; i<12; i++) {
  30.     for (j=15; j>=15-2*(i%3==0)?1:0; j--) {
  31.         x=16+j*cos(M_PI*i/6);
  32.         y=16+j*sin(M_PI*i/6);
  33.         line[INT(y)]= line[INT(y)] | (unsigned long)pow(2.0,(double)INT(x));
  34.     }
  35. }
  36.  
  37. /* On recupere l'heure */
  38. time(&epoch);
  39. tp = localtime (&epoch);
  40. strftime(tmp, 10, "%M", tp);
  41. minute=atoi(tmp);
  42. strftime(tmp, 10, "%I", tp);
  43. heure=atoi(tmp)+minute/60;
  44.  
  45. /* On dessine les aiguilles */
  46. for (i=-2; i<=9; i++) {
  47.     x=16+i*cos(M_PI*heure/6-M_PI_2);
  48.     y=16+i*sin(M_PI*heure/6-M_PI_2);
  49.     line[INT(y)]= line[INT(y)] | (unsigned long)pow(2.0,(double)INT(x));
  50. }
  51. for (i=-2; i<=15; i++) {
  52.     x=16+i*cos(M_PI*minute/30-M_PI_2);
  53.     y=16+i*sin(M_PI*minute/30-M_PI_2);
  54.     line[INT(y)]= line[INT(y)] | (unsigned long)pow(2.0,(double)INT(x));
  55. }
  56.  
  57. /* On ecrit le bitmap sur la sortie standard */
  58. for (i=0; i<32; i++) {
  59.     sprintf(res, "%08x", line[i]);
  60.     for (j=3; j>=0; j--)
  61.         if (i==31&&j==0) printf("0x%c%c};\n", res[2*j], res[2*j+1]);
  62.         else printf("0x%c%c,", res[2*j], res[2*j+1]);
  63. }
  64. }
  65.